Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 351)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.50300 11.54507 11.58662 11.62766 11.66823 11.70833 11.74799 11.78722
## [9] 11.82604 11.86448 11.90255 11.94026 11.97765 12.01470 12.05136 12.08760
## [17] 12.12341 12.15877 12.19363 12.22799 12.26182 12.29508 12.32805 12.36093
## [25] 12.39363 12.42608 12.45818 12.48984 12.52099 12.55152 12.58135 12.61040
## [33] 12.63858 12.66579 12.69298 12.72088 12.74910 12.77725 12.80495 12.83181
## [41] 12.85743 12.88144 12.90344 12.92507 12.94790 12.97145 12.99522 13.01874
## [49] 13.04151 13.06304 13.08286 13.10047 13.11539 13.12712 13.13520 13.14097
## [57] 13.14598 13.15000 13.15282 13.15420 13.15393 13.15177 13.14751 13.14091
## [65] 13.13044 13.11516 13.09580 13.07309 13.04776 13.02052 12.99211 12.96324
## [73] 12.93464 12.90704 12.88117 12.85774 12.83173 12.79890 12.76117 12.72045
## [81] 12.67864 12.63766 12.59942 12.56582 12.53878 12.51501 12.49017 12.46459
## [89] 12.43861 12.41257 12.38681 12.36166 12.33746 12.31454 12.29324 12.27390
## [97] 12.25686 12.24183 12.22820 12.21582 12.20453 12.19417 12.18459 12.17563
## [105] 12.16714 12.15895 12.15191 12.14683 12.14346 12.14157 12.14092 12.14127
## [113] 12.14238 12.14401 12.14593 12.14791 12.14969 12.15105 12.15316 12.15706
## [121] 12.16235 12.16859 12.17536 12.18222 12.18877 12.19457 12.19920 12.20368
## [129] 12.20917 12.21544 12.22228 12.22946 12.23675 12.24395 12.25083 12.25716
## [137] 12.26272 12.26729 12.27066 12.27209 12.27133 12.26883 12.26502 12.26036
## [145] 12.25529 12.25026 12.24572 12.24212 12.23990 12.23952 12.24141 12.24603
## [153] 12.25383 12.26274 12.27070 12.27820 12.28569 12.29365 12.30255 12.31286
## [161] 12.32504 12.33956 12.35797 12.38091 12.40753 12.43696 12.46834 12.50080
## [169] 12.53349 12.56554 12.59608 12.62427 12.64923 12.67010 12.69172 12.71887
## [177] 12.75063 12.78604 12.82417 12.86408 12.90484 12.94549 12.98512 13.02276
## [185] 13.05750 13.08838 13.11447 13.13482 13.14852 13.15460 13.15529 13.15349
## [193] 13.14927 13.14269 13.13383 13.12275 13.10952 13.09422 13.07691 13.05766
## [201] 13.03654 13.01362 12.98380 12.94362 12.89563 12.84237 12.78638 12.73022
## [209] 12.67642 12.62753 12.58610 12.54729 12.50505 12.46005 12.41298 12.36455
## [217] 12.31543 12.26631 12.21789 12.17084 12.12587 12.08366 12.04490 12.00686
## [225] 11.96686 11.92570 11.88419 11.84312 11.80329 11.76549 11.73053 11.69920
## [233] 11.66952 11.63922 11.60868 11.57829 11.54842 11.51946 11.49179 11.46579
## [241] 11.44183 11.42031 11.40161 11.38610 11.37240 11.35914 11.34665 11.33529
## [249] 11.32543 11.31740 11.31158 11.30832 11.30796 11.31140 11.31893 11.33000
## [257] 11.34407 11.36059 11.37902 11.39882 11.41944 11.44034 11.46097 11.48079
## [265] 11.49925 11.52190 11.55305 11.59034 11.63141 11.67390 11.71543 11.75366
## [273] 11.78621 11.81071 11.83091 11.85193 11.87351 11.89540 11.91734 11.93905
## [281] 11.96030 11.98081 12.00034 12.01861 12.03537 12.05036 12.06212 12.07006
## [289] 12.07521 12.07863 12.08134 12.08438 12.08881 12.09564 12.10594 12.11691
## [297] 12.12541 12.13194 12.13701 12.14111 12.14475 12.14842 12.15263 12.15787
## [305] 12.16465 12.17348 12.18484 12.19854 12.21388 12.23060 12.24843 12.26713
## [313] 12.28642 12.30606 12.32577 12.34530 12.36440 12.38280 12.40024 12.41646
## [321] 12.43120 12.44553 12.46052 12.47600 12.49176 12.50762 12.52339 12.53886
## [329] 12.55386 12.56817 12.58218 12.59635 12.61062 12.62494 12.63927 12.65354
## [337] 12.66771 12.68173 12.69553 12.70908 12.72232 12.73519 12.74762 12.75960
## [345] 12.77118 12.78243 12.79341 12.80418 12.81479 12.82532 12.83581
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 351)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.73728 10.82705 10.91507 11.00133 11.08581 11.16850 11.24938 11.32841
## [9] 11.40560 11.48091 11.55434 11.62585 11.69544 11.76311 11.82889 11.89283
## [17] 11.95493 12.01524 12.07378 12.13058 12.18566 12.23906 12.29056 12.33998
## [25] 12.38741 12.43289 12.47650 12.51832 12.55840 12.59682 12.63365 12.66896
## [33] 12.70280 12.73526 12.76578 12.79390 12.81984 12.84380 12.86602 12.88668
## [41] 12.90601 12.92423 12.94154 12.95623 12.96686 12.97400 12.97823 12.98014
## [49] 12.98031 12.97932 12.97775 12.97619 12.97522 12.97542 12.97737 12.97927
## [57] 12.97919 12.97754 12.97472 12.97115 12.96723 12.96338 12.95999 12.95748
## [65] 12.95573 12.95421 12.95276 12.95118 12.94930 12.94694 12.94391 12.94003
## [73] 12.93513 12.92902 12.92152 12.91244 12.90147 12.88866 12.87438 12.85901
## [81] 12.84292 12.82649 12.81009 12.79410 12.77890 12.76461 12.75095 12.73768
## [89] 12.72455 12.71131 12.69773 12.68356 12.66856 12.65248 12.63507 12.61611
## [97] 12.59533 12.57150 12.54410 12.51400 12.48207 12.44919 12.41622 12.38405
## [105] 12.35354 12.32556 12.29521 12.25807 12.21571 12.16971 12.12162 12.07304
## [113] 12.02552 11.98065 11.93998 11.90511 11.87759 11.85901 11.84590 11.83391
## [121] 11.82320 11.81398 11.80642 11.80073 11.79708 11.79568 11.79669 11.80143
## [129] 11.81058 11.82349 11.83946 11.85781 11.87786 11.89894 11.92036 11.94144
## [137] 11.96150 11.97986 11.99584 12.01286 12.03437 12.05976 12.08840 12.11967
## [145] 12.15294 12.18758 12.22298 12.25850 12.29354 12.32745 12.35962 12.38943
## [153] 12.41624 12.44308 12.47278 12.50449 12.53737 12.57056 12.60321 12.63446
## [161] 12.66346 12.68936 12.71276 12.73494 12.75603 12.77615 12.79544 12.81402
## [169] 12.83203 12.84960 12.86685 12.88391 12.90093 12.91801 12.93705 12.95942
## [177] 12.98453 13.01180 13.04064 13.07046 13.10067 13.13068 13.15991 13.18776
## [185] 13.21366 13.23700 13.25720 13.27368 13.28583 13.29309 13.29722 13.30030
## [193] 13.30220 13.30280 13.30196 13.29954 13.29542 13.28946 13.28152 13.27149
## [201] 13.25922 13.24459 13.22691 13.20592 13.18211 13.15594 13.12791 13.09848
## [209] 13.06815 13.03739 13.00668 12.97310 12.93407 12.89052 12.84342 12.79374
## [217] 12.74241 12.69041 12.63868 12.58818 12.53988 12.49472 12.45367 12.41229
## [225] 12.36639 12.31732 12.26641 12.21499 12.16439 12.11595 12.07101 12.03090
## [233] 11.99252 11.95228 11.91074 11.86846 11.82602 11.78398 11.74290 11.70337
## [241] 11.66593 11.63116 11.59963 11.57190 11.54652 11.52184 11.49809 11.47552
## [249] 11.45435 11.43483 11.41721 11.40171 11.38858 11.37790 11.36950 11.36324
## [257] 11.35900 11.35663 11.35602 11.35701 11.35948 11.36329 11.36831 11.37442
## [265] 11.38146 11.39100 11.40418 11.42021 11.43833 11.45777 11.47775 11.49751
## [273] 11.51626 11.53324 11.55114 11.57271 11.59735 11.62443 11.65333 11.68342
## [281] 11.71408 11.74469 11.77462 11.80326 11.82997 11.85414 11.87763 11.90245
## [289] 11.92825 11.95465 11.98129 12.00781 12.03382 12.05898 12.08291 12.10607
## [297] 12.12916 12.15212 12.17493 12.19754 12.21992 12.24202 12.26379 12.28522
## [305] 12.30625 12.32684 12.34695 12.36686 12.38682 12.40674 12.42656 12.44620
## [313] 12.46560 12.48468 12.50338 12.52160 12.53930 12.55639 12.57280 12.58845
## [321] 12.60329 12.61765 12.63188 12.64588 12.65960 12.67293 12.68580 12.69812
## [329] 12.70983 12.72082 12.73126 12.74134 12.75104 12.76034 12.76921 12.77764
## [337] 12.78560 12.79309 12.80006 12.80651 12.81242 12.81776 12.82250 12.82663
## [345] 12.83019 12.83319 12.83566 12.83762 12.83910 12.84012 12.84071
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 351)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.84887 10.91034 10.97077 11.03013 11.08839 11.14554 11.20154 11.25637
## [9] 11.31001 11.36243 11.41361 11.46352 11.51215 11.55955 11.60583 11.65098
## [17] 11.69502 11.73796 11.77980 11.82056 11.86024 11.89885 11.93610 11.97176
## [25] 12.00594 12.03874 12.07028 12.10065 12.12997 12.15834 12.18587 12.21266
## [33] 12.23882 12.26445 12.28870 12.31085 12.33129 12.35037 12.36848 12.38597
## [41] 12.40323 12.42060 12.43847 12.45720 12.47667 12.49657 12.51655 12.53629
## [49] 12.55545 12.57372 12.59075 12.60622 12.61979 12.63115 12.63995 12.64660
## [57] 12.65180 12.65568 12.65834 12.65991 12.66050 12.66024 12.65925 12.65763
## [65] 12.65493 12.65068 12.64502 12.63807 12.62997 12.62086 12.61087 12.60013
## [73] 12.58878 12.57694 12.56475 12.55235 12.53717 12.51733 12.49402 12.46841
## [81] 12.44170 12.41507 12.38970 12.36676 12.34745 12.32888 12.30774 12.28463
## [89] 12.26012 12.23480 12.20924 12.18404 12.15977 12.13701 12.11636 12.09838
## [97] 12.08366 12.07180 12.06174 12.05311 12.04552 12.03859 12.03194 12.02518
## [105] 12.01793 12.00981 12.00168 11.99458 11.98835 11.98285 11.97791 11.97340
## [113] 11.96916 11.96504 11.96089 11.95657 11.95191 11.94677 11.94224 11.93926
## [121] 11.93748 11.93657 11.93617 11.93594 11.93553 11.93460 11.93279 11.93019
## [129] 11.92713 11.92371 11.92000 11.91609 11.91205 11.90797 11.90393 11.90001
## [137] 11.89630 11.89287 11.88981 11.88493 11.87651 11.86525 11.85189 11.83715
## [145] 11.82175 11.80643 11.79191 11.77891 11.76816 11.76038 11.75631 11.75666
## [153] 11.76216 11.77157 11.78299 11.79617 11.81085 11.82676 11.84365 11.86125
## [161] 11.87931 11.89756 11.91821 11.94314 11.97161 12.00287 12.03617 12.07079
## [169] 12.10597 12.14097 12.17506 12.20748 12.23750 12.26437 12.29289 12.32766
## [177] 12.36769 12.41200 12.45958 12.50945 12.56061 12.61208 12.66285 12.71194
## [185] 12.75835 12.80108 12.83916 12.87157 12.89734 12.91546 12.92897 12.94139
## [193] 12.95255 12.96223 12.97024 12.97638 12.98045 12.98224 12.98157 12.97824
## [201] 12.97203 12.96275 12.94847 12.92818 12.90310 12.87444 12.84343 12.81126
## [209] 12.77917 12.74836 12.72006 12.68975 12.65293 12.61078 12.56452 12.51532
## [217] 12.46440 12.41295 12.36217 12.31325 12.26740 12.22580 12.18967 12.15283
## [225] 12.10968 12.06224 12.01253 11.96259 11.91444 11.87011 11.83162 11.80099
## [233] 11.77593 11.75273 11.73131 11.71157 11.69343 11.67682 11.66163 11.64780
## [241] 11.63523 11.62384 11.61354 11.60425 11.59952 11.60176 11.60921 11.62007
## [249] 11.63257 11.64493 11.65536 11.66210 11.66336 11.66198 11.66189 11.66290
## [257] 11.66486 11.66757 11.67088 11.67459 11.67854 11.68255 11.68646 11.69007
## [265] 11.69322 11.69403 11.69146 11.68661 11.68056 11.67442 11.66929 11.66626
## [273] 11.66642 11.67088 11.67824 11.68638 11.69523 11.70474 11.71488 11.72558
## [281] 11.73681 11.74850 11.76062 11.77311 11.78592 11.79901 11.81441 11.83351
## [289] 11.85532 11.87882 11.90302 11.92690 11.94947 11.96971 11.98662 12.00306
## [297] 12.02217 12.04340 12.06619 12.08999 12.11424 12.13840 12.16190 12.18420
## [305] 12.20474 12.22296 12.23832 12.25163 12.26414 12.27592 12.28702 12.29750
## [313] 12.30744 12.31688 12.32590 12.33455 12.34290 12.35102 12.35895 12.36678
## [321] 12.37455 12.38201 12.38887 12.39517 12.40092 12.40615 12.41088 12.41515
## [329] 12.41897 12.42237 12.42527 12.42762 12.42942 12.43070 12.43147 12.43175
## [337] 12.43157 12.43094 12.42989 12.42842 12.42657 12.42435 12.42175 12.41874
## [345] 12.41530 12.41142 12.40709 12.40230 12.39703 12.39127 12.38502
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")